package Enumerations;

public enum Directions {

	North{
		
	},
	East{
		
	},
	South{
		
	},
	West{
		
	},
	Ceiling{
		
	},
	Floor{
		
	};
	
	/**
	 * A method to get a Direction by ordinal
	 * 
	 * @param ordinal
	 * @return the direction belonging with a certain ordinal
	 * 		   |...
	 */
	public static Directions getDirectionByOrdinal(int ordinal){
		for(Directions direction : Directions.values())
			if(direction.ordinal() == ordinal)
				return direction;
			
		return null;
		
	}
	
	/**
	 * A method to get the opposite direction of the direction given
	 * 
	 * @param direction
	 * 			the direction of which you wish to know the opposite
	 * @return the direction opposite to the given direction
	 * 		   |...
	 * @throws IllegalArgumentException if no direction is entered or the direction
	 * 			is not an Direction
	 */
	public static Directions getOppositeDirection(Directions direction) throws IllegalArgumentException{
		if(direction == null || !(direction instanceof Directions)){
			throw new IllegalArgumentException();
		}
		int i = direction.ordinal();
		Directions oppositeDirection = null;
		if (i<2){
			oppositeDirection = Directions.getDirectionByOrdinal(i+2);
		}
		else if (i>1 && i<4){
			oppositeDirection = Directions.getDirectionByOrdinal(i-2);
		}
		else if (i == 4){
			oppositeDirection = Directions.getDirectionByOrdinal(5);
		}
		else if (i == 5){
			oppositeDirection = Directions.getDirectionByOrdinal(4);
		}
		return oppositeDirection;
		
	}

	/**
	 * A method to return all possible directions
	 * 
	 * @return Directions []
	 * 			an array containing all possible directions
	 * 		   |...
	 */
	public static Directions[] getAllDirections() {
		Directions[] directions = {Directions.Ceiling, Directions.East, Directions.Floor,
				Directions.North, Directions.South, Directions.West};
		return directions;
	}


}
